import Vue from 'vue';
import Vuex from 'vuex';
import createLogger from 'vuex/dist/logger';

Vue.use(Vuex);

const debug = process.env.NODE_ENV !== 'production';

export default new Vuex.Store({
  state: {
    token: '',
    userId: '',
    userInfo: {},
    isCollapse: false,
    admin: false,
    superAdmin: false,
  },
  getters: {
    getToken: (state) => state.token,
    getUserId: (state) => state.userId,
    getUserInfo: (state) => state.userInfo,
    getCollapse: (state) => state.isCollapse,
    getAdmin: (state) => state.admin,
    getSuperAdmin: (state) => state.superAdmin,
  },
  mutations: {
    changeUserId(state, userId) {
      state.userId = userId;
    },
    changeToken(state, token) {
      state.token = token;
    },
    changeUserInfo(state, userInfo) {
      state.userInfo = userInfo;
    },
    changeAdmin(state, admin) {
      state.admin = admin;
    },
    changeSuperAdmin(state, superAdmin) {
      state.superAdmin = superAdmin;
    },
    toggleSiderBar(state) {
      state.isCollapse = !state.isCollapse;
    },
  },
  actions: {
    changeToken({ commit }, token) {
      commit('changeToken', token);
    },
    changeUserId({ commit }, userId) {
      commit('changeUserId', userId);
    },
    changeUserInfo({ commit }, userInfo) {
      commit('changeUserInfo', userInfo);
    },
    changeAdmin({ commit }, admin) {
      commit('changeAdmin', admin);
    },
    changeSuperAdmin({ commit }, superAdmin) {
      commit('changeSuperAdmin', superAdmin);
    },
  },
  strict: debug,
  plugins: debug ? [createLogger()] : [],
});
